/**
 * 
 */
package com.yunyike.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yunyike.mapper.PromotionMapper;
import com.yunyike.model.Promotion;
import com.yunyike.service.IPromotionService;

/**
 * @author zhengqiang.shi
 * 2016-3-31 下午5:44:01
 */
@Service("PromotionServiceImpl")
public class PromotionServiceImpl implements IPromotionService {

	@Autowired
	private PromotionMapper promotionMapper;

	public Promotion findById(String promotionId) {
		return promotionMapper.selectByPrimaryKey(promotionId);
	}

	public int save(Promotion promotion) {
		return promotionMapper.insertSelective(promotion);
	}

	public Map<String, Promotion> selectByPromotionIds(List<String> promotionIds) {
		
		List<Promotion> promotions = promotionMapper.selectByPromotionIds(promotionIds);
		
		if(promotions == null || promotions.isEmpty()){
			return null;
		}
		
		Map<String, Promotion> promotionMap = new HashMap<String, Promotion>();
		
		for (Promotion promotion : promotions) {
			promotionMap.put(promotion.getPromotionId(), promotion);
		}
		
		return promotionMap;
	}

	/**
	 * 获取可用的促销活动
	 */
	public Map<String, Promotion> selectAvailabelByPromotionIds(List<String> promotionIds) {
		List<Promotion> promotions = promotionMapper.selectAvailabelByPromotionIds(promotionIds);
		
		if(promotions == null || promotions.isEmpty()){
			return null;
		}
		
		Map<String, Promotion> promotionMap = new HashMap<String, Promotion>();
		
		for (Promotion promotion : promotions) {
			promotionMap.put(promotion.getPromotionId(), promotion);
		}
		
		return promotionMap;
	}
	

}
